package cn.itcast.order.sentinel;

import com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.RequestOriginParser;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;

/**
 * @author: itheima
 * @create: 2022-04-28 16:11
 */
@Component
public class HaderOrgiginParse implements RequestOriginParser {
    /**
     * 编写访问授权规则逻辑：获取请求头中 口令  返回给Sentinel  由Sentinel判断是否跟授权规则中一致 如果一致则访问，不一致则拦截
     * @param request
     * @return
     */
    @Override
    public String parseOrigin(HttpServletRequest request) {
        //1.获取头细心
        String origin = request.getHeader("origin");
        //2.非空判断
        if(StringUtils.isBlank(origin)){
            origin = "blank";
        }
        return origin;
    }
}
